<?php
    class WZService_Test_Author extends \WZ_Service
    {        
        public function init()
        {
            self::run($this);
        }
        
        public static function getBooks(\WZModel_Test_Author $author)
        {
            $db = \WZService_Test_Book::getDb();
            $res = $db->select("id_author = '" . $author->getIdAuthor() . "'");
            if (is_array($res)) {
                if (count($res)) {
                    $collection = array();
                    foreach ($res as $book) {
                        $collection[] = \WZService_Test_Book::find($book->id_book);
                    }
                    return $collection;
                }
            } elseif (is_object($res)) {
                return \WZService_Test_Book::find($res->id_book);
            }
            return null;
        }
        
        public static function getSelect()
        {
            $res = self::$db->select();
            if (is_array($res)) {
                if (count($res)) {
                    $collection = array();
                    foreach ($res as $author) {
                        $collection[$author->id_author] = $author->firstname . ' ' . $author->lastname;
                    }
                    return $collection;
                }
            } elseif (is_object($res)) {
                return array($res->id_author => $res->firstname . ' ' . $res->lastname);
            }
            return null;
        }
    }